package cst.neu.yuejian_31.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.bean.CommentBean;
import cst.neu.yuejian_31.Common.Constant;

/**
 * Created by xxe on 2017/10/20.
 */

public class CommentAdapter extends RecyclerView.Adapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<CommentBean> list;

    public  CommentAdapter(Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public void setList(List<CommentBean> list){
        this.list=list;
        notifyDataSetChanged();

    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView userName,commentDetail,commentTime;
        private ImageView userPhoto;
        public ViewHolder(View itemView) {
            super(itemView);
            userName= (TextView) itemView.findViewById(R.id.textView_user_comment);
            commentDetail= (TextView) itemView.findViewById(R.id.textView_comment_detail);
            commentTime= (TextView) itemView.findViewById(R.id.textView_comment_time);
            userPhoto= (ImageView) itemView.findViewById(R.id.imageView_userphoto_comment);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=layoutInflater.inflate(R.layout.item_comment,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//        final CcourseBean ccourseBean=list.get(position);
//        if(ccourseBean==null)
//            return;
        final CommentBean commentBean=list.get(position);
        if (commentBean==null)
            return;
        ViewHolder viewHolder= (ViewHolder) holder;
        viewHolder.userName.setText(commentBean.getUsername());
        viewHolder.commentTime.setText(commentBean.getComment_time());
        viewHolder.commentDetail.setText(commentBean.getComment_text());
        Picasso.with(context).load(Constant.USER_URL+commentBean.getUser_pic()).into(viewHolder.userPhoto);

    }

    @Override
    public int getItemCount() {
        if (list==null)
            return 0;
        else
            return list.size();
    }
}
